// packageE/memberorder/memberorder.js
const app = getApp();
Component({
  properties: {
    datas: {
      type: null,
    },
    component_id: {
      type: null,
    }
  },
  // 私有数据，可用于模板渲染
  data: {
    diyStyle: null
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
      // 在组件实例进入页面节点树时执行
      this.getData();
      this.setData({
        diyStyle: `
          --preview_color: ${this.data.datas.preview_color};
          --module_bgcolor: ${this.data.datas.module_bgcolor};
          --padding_top: ${this.data.datas.padding_top}px;
          --padding_bottom: ${this.data.datas.padding_bottom}px;
          --padding_left: ${this.data.datas.padding_left}px;
          --padding_right: ${this.data.datas.padding_right}px;
          --border_radius: ${this.data.datas.border_radius}px;
          --level_color: ${this.data.datas.level_color};
          --level_size: ${this.data.datas.level_size}px;
          --growth_color: ${this.data.datas.growth_color};
          --growth_size: ${this.data.datas.growth_size}px;
          --validity_color: ${this.data.datas.validity_color};
          --validity_size: ${this.data.datas.validity_size}px;
          --icon_color: ${this.data.datas.icon_color};
          --icon_size: ${this.data.datas.icon_size}px;
        `
      });
    },
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {},

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },
  methods: {
    getData() {
      let urlStr = app.getNetAddresss('member.member.decorateMemberLevel');
      app._getNetWork({
        url: urlStr,
        data: {},
        success: (resdata)=> {
          let { data } = resdata;
          if (data.result == 0) return app.tips(data.msg);
          this.setData({
            current_level: data.data.current_level,
            condition: data.data.condition,
          })
        },
        fail: function(res) {
          console.log(res);
        }
      });
    },
    toUrl(e){
      let url = e.currentTarget.dataset.url;
      wx.navigateTo({
        url: url,
        fail: ()=> {
          wx.reLaunch({
            url: url
          })
        }
      });
    }
  },
  observers: {},
});